package cn.hnu.qq.client.panel;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.File;
import java.io.IOException;
import java.util.Set;

import javax.imageio.ImageIO;
import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JToolBar;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import cn.hnu.qq.client.controller.CenterController;
import cn.hnu.qq.client.controller.FriendsListController;
import cn.hnu.qq.client.controller.ListenClientMessageThread;
import cn.hnu.qq.client.controller.ListenServerMessageThread;
import cn.hnu.qq.client.controller.SingleChartController;
import cn.hnu.qq.client.event.MessageEvent;
import cn.hnu.qq.client.listener.MessageListener;
import cn.hnu.qq.entity.Crowd;
import cn.hnu.qq.entity.TaskEvent;
import cn.hnu.qq.entity.User;
import cn.hnu.qq.entity.message.AddFriendMessage;
import cn.hnu.qq.entity.message.CreateCrowdMessage;
import cn.hnu.qq.entity.message.DeleteFriendMessage;
import cn.hnu.qq.entity.message.DownLoadFileMessage;
import cn.hnu.qq.entity.message.ExitCrowdMessage;
import cn.hnu.qq.entity.message.JoinCrowdMessage;
import cn.hnu.qq.entity.message.Message;
import cn.hnu.qq.entity.message.SendFileMessage;
import cn.hnu.qq.entity.message.UploadFileMessage;
import cn.hnu.qq.frame.ClientFrame;
import cn.hnu.qq.frame.CreateCrowdDialog;
import cn.hnu.qq.frame.CrowdChartDialog;
import cn.hnu.qq.frame.FileListDialog;
import cn.hnu.qq.frame.FileWaitingDialog;
import cn.hnu.qq.frame.SearchDialog;
import cn.hnu.qq.frame.SendEmailDialog;
import cn.hnu.qq.frame.SingleChartDialog;
import cn.hnu.qq.global.CellRenderer;
import cn.hnu.qq.global.FileReceiver;
import cn.hnu.qq.global.FileSender;
import cn.hnu.qq.global.ImageUtil;
import cn.hnu.qq.global.MessageType;
import javax.swing.SwingConstants;

/**
 * 好友列表面板
 * 
 * @author jared
 * 
 */
public class FriendsListPanel extends JPanel implements MouseListener,
		MessageListener, ActionListener ,ChangeListener{

	private JList<User> friendsList = new JList<User>();

	private JList<Crowd> crowdsList = new JList<Crowd>();;

	private JTabbedPane tabbedPane;

	private FriendsListController controller = FriendsListController
			.getInstance();

	private int index = 0;

	private JMenuBar menubar = new JMenuBar();

	private JToolBar JToolBar = new JToolBar();
	
	private static ImageIcon editIcon = ImageUtil.getImageIcon("edit.png");

	private static ImageIcon searchIcon = ImageUtil.getImageIcon("search.png");
	
	private JButton sendEmailButton;

	private JButton sendFileButton;

	private JButton exitCrowdButton;

	private JButton deleteFriendButton;

	private JButton createCrowdButton;

	private JLabel imageLabel;
	
	@Override
	protected void paintComponent(Graphics g) {
		Image image = null;
		try {
			image = ImageIO.read(new File("src/main/java/image/04.jpg"));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		};
				
		g.drawImage(image, 0, 0, this.getWidth(), this.getHeight(), this);

	}

	/**
	 * Create the panel.
	 */
	public FriendsListPanel() {

		setLayout(null);

		JPanel panel = new JPanel(){
			@Override
			protected void paintComponent(Graphics g) {
				Image image = null;
				try {
					image = ImageIO.read(new File("src/main/java/image/11.jpg"));
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				};
						
				g.drawImage(image, 0, 0, this.getWidth(), this.getHeight(), this);

			}
		};
		panel.setBounds(12, 10, 192, 80);
		add(panel);
		panel.setLayout(new BorderLayout(0, 0));

		imageLabel = new JLabel(controller.getCurUser().getAcount());
		imageLabel.setHorizontalAlignment(SwingConstants.CENTER);
		panel.add(imageLabel, BorderLayout.CENTER);

		tabbedPane = new JTabbedPane(JTabbedPane.TOP);
		tabbedPane.setBounds(12, 100, 193, 356);
		add(tabbedPane);
		JScrollPane scrollPane_2 = new JScrollPane();
		JScrollPane scrollPane_3 = new JScrollPane();
		friendsList.addMouseListener(this);
		friendsList.setCellRenderer(new CellRenderer());
		scrollPane_2.setViewportView(friendsList);
		scrollPane_3.setViewportView(crowdsList);
		crowdsList.addMouseListener(this);
		crowdsList.setCellRenderer(new CellRenderer());
		tabbedPane.add(scrollPane_2, 0);
		tabbedPane.setTitleAt(0, "好友列表");
		tabbedPane.add(scrollPane_3, 1);
		tabbedPane.setTitleAt(1, "群组列表");
		
		tabbedPane.addMouseListener(this);
		tabbedPane.addChangeListener(this);
		this.setSize(213, 638);
		setFriendsList(controller.getCurUser().getFriends());
		setCrowdsList(controller.getCurUser().getCrowds());

		JPanel panel_2 = new JPanel(){
			@Override
			protected void paintComponent(Graphics g) {
				Image image = null;
				try {
					image = ImageIO.read(new File("src/main/java/image/06.jpg"));
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				};
						
				g.drawImage(image, 0, 0, this.getWidth(), this.getHeight(), this);

			}
		};
		panel_2.setBounds(12, 468, 192, 160);
		add(panel_2);
		GridBagLayout gbl_panel_2 = new GridBagLayout();
		gbl_panel_2.columnWidths = new int[] { 0, 0, 0, 0, 0, 0 };
		gbl_panel_2.rowHeights = new int[] { 0, 0, 0, 0, 0, 0 };
		gbl_panel_2.columnWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0,
				Double.MIN_VALUE };
		gbl_panel_2.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE };
		panel_2.setLayout(gbl_panel_2);
		
		sendFileButton = new JButton("发送文件");
		sendFileButton.setActionCommand("send file");
		sendFileButton.addActionListener(this);
		
		sendEmailButton = new JButton("发送邮件");
		sendEmailButton.setActionCommand("send email");
		GridBagConstraints gbc_sendEmailButton = new GridBagConstraints();
		gbc_sendEmailButton.insets = new Insets(0, 0, 5, 5);
		gbc_sendEmailButton.gridx = 0;
		gbc_sendEmailButton.gridy = 0;
		panel_2.add(sendEmailButton, gbc_sendEmailButton);
		sendEmailButton.addActionListener(this);
		
				JButton button_1 = new JButton("");
				button_1.setActionCommand("search");
				button_1.addActionListener(this);
				
				createCrowdButton = new JButton("创建群组");
				createCrowdButton.setActionCommand("create crowd");
				createCrowdButton.addActionListener(this);
				GridBagConstraints gbc_button_5 = new GridBagConstraints();
				gbc_button_5.insets = new Insets(0, 0, 5, 5);
				gbc_button_5.gridx = 2;
				gbc_button_5.gridy = 0;
				panel_2.add(createCrowdButton, gbc_button_5);
				button_1.setIcon(searchIcon);
				GridBagConstraints gbc_button_1 = new GridBagConstraints();
				gbc_button_1.insets = new Insets(0, 0, 5, 5);
				gbc_button_1.gridx = 0;
				gbc_button_1.gridy = 1;
				panel_2.add(button_1, gbc_button_1);
		GridBagConstraints gbc_btnNewButton = new GridBagConstraints();
		gbc_btnNewButton.insets = new Insets(0, 0, 5, 5);
		gbc_btnNewButton.gridx = 2;
		gbc_btnNewButton.gridy = 1;
		panel_2.add(sendFileButton, gbc_btnNewButton);
		
		exitCrowdButton = new JButton("退出群组");
		exitCrowdButton.setActionCommand("exit crowd");
		exitCrowdButton.addActionListener(this);
		
		deleteFriendButton = new JButton("删除好友");
		deleteFriendButton.setActionCommand("delete friend");
		deleteFriendButton.addActionListener(this);
		GridBagConstraints gbc_button_4 = new GridBagConstraints();
		gbc_button_4.insets = new Insets(0, 0, 5, 5);
		gbc_button_4.gridx = 0;
		gbc_button_4.gridy = 2;
		panel_2.add(deleteFriendButton, gbc_button_4);
		exitCrowdButton.setEnabled(false);
		GridBagConstraints gbc_button_3 = new GridBagConstraints();
		gbc_button_3.insets = new Insets(0, 0, 5, 5);
		gbc_button_3.gridx = 2;
		gbc_button_3.gridy = 2;
		panel_2.add(exitCrowdButton, gbc_button_3);

		// TODO 换个方法 用于改善界面
		controller.getClient().refreshFriendsListPanel(this);
		// 添加消息机制
		ListenClientMessageThread.getInstance().addMessageListener(this);
	
		// 初始化 单聊对话框，但不显示
		SingleChartDialog.getInstance();
		// 群聊
		CrowdChartDialog.getIntance();

		ListenServerMessageThread.getInstance().addMessageListener(this);
	}

	public void setFriendsList(Set<User> users) {
		DefaultListModel<User> model = new DefaultListModel<User>();
		for (User user : users) {
			model.addElement(user);
		}
		friendsList.setModel(model);
	}

	public void setCrowdsList(Set<Crowd> corwds) {
		DefaultListModel<Crowd> model = new DefaultListModel<Crowd>();
		for (Crowd Crowd : corwds) {
			model.addElement(Crowd);
		}
		crowdsList.setModel(model);
	}

	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					ClientFrame window = new ClientFrame();
					window.refreshPanel(new FriendsListPanel());
					window.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	public void mouseClicked(MouseEvent e) {
		if (e.getClickCount() % 2 == 0 && e.getButton() == MouseEvent.BUTTON1) {
			if (tabbedPane.getSelectedIndex() == 0) {
				JOptionPane.showMessageDialog(controller.getClient(), "ffff");
				User user = friendsList.getSelectedValue();
				if (controller.getSingDialog() == null) {
					CenterController.setSingDialog(SingleChartDialog
							.getInstance());
				}
				if (!controller.getSingDialog().isVisible()) {
					controller.getSingDialog().setVisible(true);
				}
				controller.getSingDialog().createChartTab(user);
			}
			if (tabbedPane.getSelectedIndex() == 1) {
				JOptionPane.showMessageDialog(controller.getClient(), "cccc");
				Crowd crowd = crowdsList.getSelectedValue();
				if (controller.getCrowdDialog() == null) {
					CenterController.setCrowdDialog(CrowdChartDialog
							.getIntance());
				}
				if (!controller.getCrowdDialog().isVisible()) {
					controller.getCrowdDialog().setVisible(true);
				}
				controller.getCrowdDialog().createChartTab(crowd);
			}
		}

	}

	private void maybeShowCrowdPopup(MouseEvent e) {
		
		
	}

	private void maybeShowFriendPopup(MouseEvent e) {
		if(e.isPopupTrigger() && friendsList.getSelectedIndex() != -1){
		System.err.println("进入if");
			System.err.println(e.getComponent());
			System.err.println(e.getX()+":"+e.getY());
			JPopupMenu p = new JPopupMenu();
			p.add(new JMenuItem("添加好友"));
			friendsList.add(p);
			p.show(tabbedPane, e.getX(), e.getY());
			//TODO 右键菜单的问题
		}
	}

	public void mousePressed(MouseEvent e) {
	}

	public void mouseEntered(MouseEvent e) {
	}

	public void mouseExited(MouseEvent e) {
	}

	public void messageArrived(MessageEvent event) {
		Message message = event.getSource();
		if (message.getMessageType() == MessageType.CHART) {
			SingleChartDialog scd = SingleChartDialog.getInstance();
			if (scd.isVisible() == false) {
				scd.setVisible(true);
			}
			return;
		}
		if (message.getMessageType() == MessageType.CROWD_CHART) {
			CrowdChartDialog ccd = CrowdChartDialog.getIntance();
			if (ccd.isVisible() == false) {
				ccd.setVisible(true);
			}
			return;
		}
		if(message.getMessageType() == MessageType.LEAVE_WORDS){
			TaskEvent task = (TaskEvent) message;
			User user = task.getMaker();
			if (controller.getSingDialog() == null) {
				CenterController.setSingDialog(SingleChartDialog
						.getInstance());
			}
			if (!controller.getSingDialog().isVisible()) {
				controller.getSingDialog().setVisible(true);
			}
			DefaultModelChartPanel dmcp = controller.getSingDialog().createChartTab(user);
			dmcp.insertMessage(task);
		}
		if (message.getMessageType() == MessageType.ADD_FRIEND) {
			final TaskEvent task = (TaskEvent) message;
			final String info = task.getMaker().getAcount() + "请求添加你为好友";
			int choose = JOptionPane.showConfirmDialog(this, info, "添加好友请求",
					JOptionPane.OK_CANCEL_OPTION);
			if (choose == JOptionPane.OK_OPTION) {
				controller.confirmAddFriend(task);
				((DefaultListModel<User>) friendsList.getModel())
						.addElement(task.getMaker());
				return;
			}

			return;
		}
		if (message.getMessageType() == MessageType.JION_CROWD) {
			final TaskEvent task = (TaskEvent) message;
			final String info = task.getMaker().getAcount() + "请求加入"
					+ task.getSource() + "，是否同意？";
			int choose = JOptionPane.showConfirmDialog(this, info, "加入群组请求",
					JOptionPane.OK_CANCEL_OPTION);
			if (choose == JOptionPane.OK_OPTION) {
				controller.confirmJoinCrowd(task);
				return;
			}
			return;
		}
		if (message.getMessageType() == MessageType.CONFIRM_ADD_FRIEND) {
			AddFriendMessage adm = (AddFriendMessage) message;
			User user = new User();
			user.setAcount(adm.getFriend());
			DefaultListModel<User> model = (DefaultListModel<User>) friendsList.getModel();
			if(!model.contains(user)){
				model.addElement(user);
			}
			return;
		}
		if (message.getMessageType() == MessageType.CONFIRM_JOIN_CROWD) {
			final JoinCrowdMessage task = (JoinCrowdMessage) message;
			Crowd crowd = new Crowd();
			crowd.setCrowdName(task.getCrowd());
			DefaultListModel<Crowd> model = (DefaultListModel<Crowd>) crowdsList.getModel();
			if(!model.contains(crowd)){
				model.addElement(crowd);
			}
			return;
		}
		if(message.getMessageType() == MessageType.DELETE_FRIEND){
			DeleteFriendMessage dfm = (DeleteFriendMessage) message;
			if(dfm.getUser().equals(controller.getCurUser().getAcount())){
				//删除好友主动方
				User user = new User();
				user.setAcount(dfm.getFriend());
				JOptionPane.showMessageDialog(this, "删除好友"+dfm.getFriend()+"成功");
				DefaultListModel<User> model = (DefaultListModel<User>) friendsList.getModel();
				model.removeElement(user);
				controller.getCurUser().getFriends().remove(user);
				SingleChartDialog.getInstance().closeChartTab(user);
			}else if(dfm.getFriend().equals(controller.getCurUser().getAcount())){
				//删除好友被动方
				User user = new User();
				user.setAcount(dfm.getUser());
				DefaultListModel<User> model = (DefaultListModel<User>) friendsList.getModel();
				model.removeElement(user);
				controller.getCurUser().getFriends().remove(user);
				SingleChartDialog.getInstance().closeChartTab(user);
			}
		}
		if(message.getMessageType() == MessageType.EXIT_CROWD){
			ExitCrowdMessage ecm = (ExitCrowdMessage) message;
			if(ecm.getUser().equals(controller.getCurUser().getAcount())){
				//主动退出者
				Crowd c = new Crowd();
				c.setCrowdName(ecm.getCrowd());
				DefaultListModel<Crowd> model = (DefaultListModel<Crowd>) crowdsList.getModel();
				model.removeElement(c);
				controller.getCurUser().getCrowds().remove(c);
				CrowdChartDialog.getIntance().closeChartTab(c);
			}
		}
		if(message.getMessageType() == MessageType.SUCCESS_CREATE_CROWD){
			CreateCrowdMessage ccm = (CreateCrowdMessage) message;
			Crowd crowd = new Crowd();
			crowd.setCrowdName(ccm.getCrowdName());
			DefaultListModel<Crowd> model = (DefaultListModel<Crowd>) crowdsList.getModel();
			model.addElement(crowd);
			controller.getCurUser().joinGroup(crowd);
		}
		if(message.getMessageType() == MessageType.SEND_FILE){
			SendFileMessage sfm = (SendFileMessage) message;
			if(sfm.getChoose() == SendFileMessage.NOT_CHOOSE){
				int choose = JOptionPane.showConfirmDialog(this, "用户"+sfm.getUser()+"即将发送"+sfm.getFileName()+"文件，文件大小："+sfm.getFileSize()+",是否接收？",
						"文件传输", JOptionPane.OK_CANCEL_OPTION);
				if(choose == JOptionPane.OK_OPTION){
					User user = controller.getCurUser().findFriend(sfm.getUser());
					final FileReceiver fr = controller.setupSendFile(user,sfm);
					final FileWaitingDialog dialog = new FileWaitingDialog(controller.getClient(),false);
					fr.setProgress(dialog.getProgressBar());
					dialog.setVisible(true);
					dialog.setModal(false);
					dialog.setInfo("文件正在接收中，请稍等....");
					fr.start();
					EventQueue.invokeLater(new Runnable() {
						public void run() {
							while(!fr.isSendOver()){
								try {
									Thread.sleep(100);
								} catch (InterruptedException e) {
									e.printStackTrace();
								}
							}
							dialog.setInfo("文件接收完成");
						}
					});
					return;
				}
			}
			if(sfm.getChoose() == SendFileMessage.OK){
					File f = new File(sfm.getAbsPath());
					final FileSender fs = new FileSender(f,sfm.getIp(), sfm.getPort());
					final FileWaitingDialog dialog = new FileWaitingDialog(controller.getClient(),false);
					fs.setProgress(dialog.getProgressBar());
					dialog.setVisible(true);
					dialog.setModal(false);
					dialog.setInfo("文件正在发送中，请稍等....");
					fs.start();
					EventQueue.invokeLater(new Runnable() {
						public void run() {
							while(!fs.isSendOver()){
								try {
									Thread.sleep(100);
								} catch (InterruptedException e) {
									e.printStackTrace();
								}
							}
							dialog.setInfo("文件发送完成");
						}
					});
					return;
			}
			if(sfm.getChoose() == SendFileMessage.CANCEL){
				JOptionPane.showMessageDialog(this, "对方拒绝接收文件");
				return;
			}
		}
		if(message.getMessageType() == MessageType.UPLOAD_FILE){
			UploadFileMessage sfm = (UploadFileMessage) message;
			File f = new File(sfm.getAbsolutePath());
			final FileSender fs = new FileSender(f,controller.getServerIp(), sfm.getPort());
			final FileWaitingDialog dialog = new FileWaitingDialog(controller.getClient(),false);
			fs.setProgress(dialog.getProgressBar());
			dialog.setVisible(true);
			dialog.setModal(false);
			dialog.setInfo("文件正在发送中，请稍等....");
			fs.start();
			EventQueue.invokeLater(new Runnable() {
				public void run() {
					while(!fs.isSendOver()){
						try {
							Thread.sleep(100);
						} catch (InterruptedException e) {
							e.printStackTrace();
						}
					}
					dialog.setInfo("文件发送完成");
				}
			});
			return;
		}
		if(message.getMessageType() == MessageType.DOWNLOAD_FILE){
			DownLoadFileMessage dlfm = (DownLoadFileMessage) message;
			if(dlfm.getSelectedFile() == null || dlfm.getSelectedFile().equals("")){
				FileListDialog fld = new FileListDialog();
				fld.setFiels(dlfm.getFiles());
				fld.setVisible(true);
			}else{
				
			}
		}
		if(message.getMessageType() == MessageType.ERROR){
			JOptionPane.showMessageDialog(this, "程序出错");
		}
	}

	public void actionPerformed(ActionEvent e) {
		if (e.getActionCommand().equals("search")) {
			JDialog dialog = new SearchDialog(controller.getClient(), true);
			dialog.setVisible(true);
			return;
		}
		if(e.getActionCommand().equals("delete friend")){
			User user = friendsList.getSelectedValue();
			if(user == null){
				JOptionPane.showMessageDialog(this, "请选择一个好友");
				return;
			}
			String info = "删除好友"+user;
			int choose = JOptionPane.showConfirmDialog(this, info,"删除好友" ,JOptionPane.OK_CANCEL_OPTION);
			if(choose == JOptionPane.OK_OPTION){
				controller.deleteFriend(user);
			}
		}
		if(e.getActionCommand().equals("exit crowd")){
			Crowd crowd = crowdsList.getSelectedValue();
			if(crowd == null){
				JOptionPane.showMessageDialog(this, "请选择一个群组");
				return;
			}
			String info = "退出群组"+crowd;
			int choose = JOptionPane.showConfirmDialog(this, info,"退出群组" ,JOptionPane.OK_CANCEL_OPTION);
			if(choose == JOptionPane.OK_OPTION){
				controller.exitCrowd(crowd);
			}
		}
		if(e.getActionCommand().equals("create crowd")){
			JDialog dialog = new CreateCrowdDialog(controller.getClient(),true);
			dialog.setVisible(true);
			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		}
		if(e.getActionCommand().equals("send email")){
			if(tabbedPane.getSelectedIndex() == 0){
				SendEmailDialog sem = SendEmailDialog.getInstance();
				User user = friendsList.getSelectedValue();
				if(user == null){
					JOptionPane.showMessageDialog(this, "请选择收件人");
					return;
				}
				sem.setSender(user);
				sem.setVisible(true);
			}else{
				SendEmailDialog sem = SendEmailDialog.getInstance();
				Crowd crowd = crowdsList.getSelectedValue();
				if(crowd == null){
					JOptionPane.showMessageDialog(this, "请选择群发对象");
					return;
				}
				sem.setSender(crowd);
				sem.setVisible(true);
			}
			
			
		}
		if(e.getActionCommand().equals("send file")){
			JFileChooser jfc = new JFileChooser("/");
			int state = jfc.showOpenDialog(this);
			
			if(state == JFileChooser.APPROVE_OPTION){
				File file = jfc.getSelectedFile();
				if(file.isDirectory()){
					JOptionPane.showMessageDialog(this, "暂不支持文件夹传输，请重新选择");
					return;
				}
				User user = friendsList.getSelectedValue();
				if(user == null){
					JOptionPane.showMessageDialog(this, "请选择传输对象");
					return;
				}
				if(user.getIp() == null || user.getUserClientPort() == null){
					JOptionPane.showMessageDialog(this, "暂不支持离线文件传输，请等待用户上线");
					return;
				}
				controller.sendFileMessage(user,file);
			}
		}
	}

	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	public void stateChanged(ChangeEvent e) {
		if(tabbedPane.getSelectedIndex() == 0){
			if(sendFileButton != null){
				sendFileButton.setEnabled(true);
			}
			if(exitCrowdButton != null){
				exitCrowdButton.setEnabled(false);
			}
			if(deleteFriendButton != null){
				deleteFriendButton.setEnabled(true);
			}
		}else{
			if(sendFileButton != null){
				sendFileButton.setEnabled(false);
			}
			if(exitCrowdButton != null){
				exitCrowdButton.setEnabled(true);
			}
			if(deleteFriendButton != null){
				deleteFriendButton.setEnabled(false);
			}
		}
		
	}

}
